package master.userInterface;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;


import master.*;
import master.event.NetworkEvent;
import master.event.NetworkEventListener;

public class NetworkDisplayPanel extends JPanel implements NetworkEventListener, MouseMotionListener,MouseListener{
	QuantumNetwork myD;
	public static Color networkColor = new Color(210,180,140);
	public static Color backgroundColor = new Color(112,128,144);
	
	int mouseX=0, mouseY=0;
	int xOffset = 0, yOffset = 0, savedXOffs = 0, savedYOffs = 0;
	
	public NetworkDisplayPanel(QuantumNetwork myD){
		this.myD = myD;
		myD.addNetworkListener(this);
		this.setBackground(backgroundColor);
		this.addMouseMotionListener(this);
		this.addMouseListener(this);
	}
	public void paintComponent(Graphics g){
		((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		super.paintComponent(g);
		g.setColor(networkColor);
		myD.draw(g, xOffset,yOffset, 30);
	}
	
	public void networkEvent(NetworkEvent e) {
		repaint();
	}
	
	public void mouseDragged(MouseEvent e) {
		xOffset = e.getX() -mouseX + savedXOffs;
		yOffset = e.getY() -mouseY + savedYOffs;
		
		repaint();
	}
	public void mouseMoved(MouseEvent arg0) {}
	
	
	public void mouseClicked(MouseEvent arg0) {}
	public void mouseEntered(MouseEvent arg0) {}
	public void mouseExited(MouseEvent arg0) {}
	public void mousePressed(MouseEvent e) {
		mouseX = e.getX();
		mouseY = e.getY();
	}
	public void mouseReleased(MouseEvent arg0) {
		savedXOffs = xOffset;
		savedYOffs = yOffset;
	}
}
